<template>
  <tab-bar>
    <div class="home" slot="main">
      <div class="index-banner" :style="`height:${bannerHt}px`">
        <mt-swipe :auto="5000">
          <mt-swipe-item v-for="(val, key) in banners" :key="key">
            <img :src="$file + val.caad03" alt="">
          </mt-swipe-item>
        </mt-swipe>
      </div>
      <div class="short-cut">
        <router-link to="/home/more/a" class="item">
          <i class="xffont xf-time"></i>
          <span>我要约</span>
        </router-link>
        <router-link to="/home/more/b" class="item">
          <i class="xffont xf-rili"></i>
          <span>我要办</span>
        </router-link>
        <router-link to="/home/more/c" class="item">
          <i class="xffont xf-search"></i>
          <span>我要查</span>
        </router-link>
        <router-link to="/suggest" class="item">
          <i class="xffont xf-message"></i>
          <span>我要说</span>
        </router-link>
      </div>
      <div class="rollNotice">
        <div class="left">
          <img src="./zixun.png" alt="">
          <span>动态</span>
        </div>
        <yd-rollnotice :autoplay="3000">
          <yd-rollnotice-item v-for="(val, key) in list" :key="key">
            <router-link :to="`/home/news?canc11=${val.canc11 || ''}&cand01=${val.cand01 || ''}`" class="roll-notice-item">{{val.cand03}}</router-link>
          </yd-rollnotice-item>
        </yd-rollnotice>
      </div>
      <div class="public-service">
        <span class="common-title">公共服务</span>
        <div class="service-list">
          <router-link to="/home/more/1" class="service-item"><img src="./public-1.png" alt=""></router-link>
          <router-link to="/home/more/2" class="service-item"><img src="./public-2.png" alt=""></router-link>
          <router-link to="/home/more/3" class="service-item"><img src="./public-3.png" alt=""></router-link>
          <router-link to="/home/more/4" class="service-item"><img src="./public-4.png" alt=""></router-link>
        </div>
      </div>
      <div class="public-service">
        <span class="common-title">常办事项</span>
        <div class="short-cut">
          <router-link :to="val.link" class="item" v-for="(val, key) in hots" :key="key">
            <i class="xffont" :class="val.icon"></i>
            <span>{{val.title}}</span>
          </router-link>
        </div>
      </div>
    </div>
    <transition name="router" mode="out-in">
      <router-view class="fixed-router"></router-view>
    </transition>
  </tab-bar>
</template>
<script>
  import TabBar from '../../layouts/tab-bar/index.vue'
  import {getServices} from '../../common/js/service_list'

  export default {
    components: {
      TabBar
    },
    data() {
      return {
        bannerHt: 200,
        hots: getServices(['/roll-in-1', '/pay', '/activities', '/query']),
        list: [],
        banners: []
      }
    },
    methods: {
      getNews() {
        this.$post('/sapi/news/get/article/list', {
          canc11: 'XWDT',
          page: 1,
          rows: 10
        }, loading => {
          this.loading = loading
        }).then(res => {
          this.list = this.list.concat(res.data.articleList)
        })
      },
      getBanners() {
        this.$post('/sapi/advert/get/ad/web/list', {
          indent: 'zwwgw_banner'
        }).then(res => {
          this.banners = res.data.adWebList
        })
      }
    },
    created() {
      this.bannerHt = document.body.clientWidth * 8 / 15
      this.getNews()
      this.getBanners()
    }
  }
</script>
<style lang="scss" scoped>
  @import "../../common/style/variable";
  .index-banner{
    img{
      width: 100%;
    }
  }
  .short-cut{
    display: flex;
    margin: 0 0 2px 0;
    padding: .14rem 0;
    background: #fff;
    flex-wrap: wrap;
    .item{
      width: 25%;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: .1rem .1rem;
      text-align: center;
      border-radius: 5px;
      @include active;
      .xffont{
        font-size: .5rem;
        color: $primary;
      }
      span{
        margin: .1rem 0 0 0;
      }
    }
  }
  .rollNotice{
    display: flex;
    background: #fff;
    padding: .1rem .1rem;
    margin: 0 0 4px 0;
    .roll-notice-item{
      display: inline-block;
      width: 100%;
      @include ellipsis;
    }
    .left{
      white-space: nowrap;
      padding: 0 .1rem;
      align-items: center;
      display: flex;
      img{
        width: .85rem;
      }
      span{
        line-height: .33rem;
        margin: 0 .1rem;
        display: inline-block;
        padding: .05rem .1rem;
        border-radius: .15rem;
        background: #eb6c00;
        color: #fff;
      }
    }
  }
  .public-service{
    padding: .2rem;
    background: #fff;
    margin: 0 0 4px 0;
  }
  .common-title{
    display: inline-block;
    padding: 0 0 0 .2rem;
    border-left: 5px solid $primary;
    font-size: .3rem;
    font-weight: 600;
  }
  .service-list{
    display: flex;
    flex-wrap: wrap;
    padding: .1rem 0;
    .service-item{
      width: 50%;
      padding: .05rem;
      display: block;
      img{
        width: 100%;
        height: auto;
      }
    }
  }
</style>
